package com.gitee.elf.core.data

import com.google.gson.*
import java.lang.reflect.Type

class DataBoolean(val value : Boolean) : Data {

    override fun getValue(): Any {
        return value
    }

    override fun toString(): String {
        return value.toString()
    }

    override fun clone(): DataBoolean {
        return DataBoolean(value)
    }

    @SerializerType(DataBoolean::class)
    class Serializer : JsonSerializer<DataBoolean>, JsonDeserializer<DataBoolean> {
        override fun serialize(src: DataBoolean?, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement {
            return JsonPrimitive("${src!!.value}b")
        }

        override fun deserialize(json: JsonElement?, typeOfT: Type?, context: JsonDeserializationContext?): DataBoolean {
            return DataBoolean(json!!.asBoolean)
        }


    }

}